package com.gooapple.notepad.util;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.gooapple.notepad.R;
import com.gooapple.notepad.basic.BasicAdapter;
import com.gooapple.notepad.model.HomeInfo;

public class HomeListAdapter extends BasicAdapter {
	private List<HomeInfo> homeInfos;
	public void setHomeInfos(List<HomeInfo> homeInfos) {
		this.homeInfos = homeInfos;
	}

	private LayoutInflater inflater;

	public HomeListAdapter(List<HomeInfo> homeInfos, Context context) {
		super();
		this.homeInfos = homeInfos;
		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		if (homeInfos != null) {
			return homeInfos.size();
		} else {
			return 0;
		}
	}

	@Override
	public Object getItem(int position) {
		return homeInfos.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.home_item, null);
			viewHolder = new ViewHolder();
			viewHolder.infoText = (TextView) convertView
					.findViewById(R.id.home_info_text);
			viewHolder.detailText = (TextView) convertView
					.findViewById(R.id.home_info_text_detail);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		viewHolder.detailText.setText(homeInfos.get(position)
				.getHomeTextDetail());
		viewHolder.infoText.setText(homeInfos.get(position).getHomeText());
		convertView.setTag(viewHolder);
		return convertView;
	}

	class ViewHolder {
		TextView infoText;
		TextView detailText;
	}

}
